package service;

import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

public class ActiveMQService {

	private static ActiveMQConnectionFactory connectionFactory;
	public static Connection connection;
	public static Session session;
	public static Destination destination;
	private static boolean transacted = false;

	public static void setUp(String watQueue) throws JMSException {
		connectionFactory = new ActiveMQConnectionFactory(
				ActiveMQConnection.DEFAULT_USER,
				ActiveMQConnection.DEFAULT_PASSWORD,
				"failover:tcp://localhost:61616");
		connection = connectionFactory.createConnection();
		connection.start();
		session = connection
				.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
		destination = session.createQueue(watQueue);
	}

	public static void sendContentSMS(String str) throws JMSException {
		setUp("contentSMS");
		MessageProducer producer = session.createProducer(destination);
		producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
		TextMessage message = session.createTextMessage(str);
		producer.send(message);
	}

	public static void sendImageSMS(String str) throws JMSException {
		setUp("imageSMS");
		MessageProducer producer = session.createProducer(destination);
		producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
		TextMessage message = session.createTextMessage(str);
		producer.send(message);
	}

}
